package com.dqs.controller;

import com.dqs.comment.result.Result;
import com.dqs.po.EmployeePo;
import com.dqs.service.EmployeeService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @GetMapping
    public Result<?> findAllEmployeePo(Integer employeeWorkId, String employeeName, String employeeAddress){

        List<EmployeePo> employeePos = employeeService.selectEmployeePo(employeeWorkId, employeeName, employeeAddress);
        System.out.println("employeePos = " + employeePos);
        Result<?> success = Result.success(employeePos);
        System.out.println("success = " + success);
        return success;
    }

    @PutMapping
    public Result<?> updateEmployeeById(@RequestBody EmployeePo employeePo){
        employeeService.updateEmployeeById(employeePo);
        return Result.success();
    }

    @PostMapping
    public Result<?> insertEmployeePo(@RequestBody EmployeePo employeePo) {
        employeeService.insertEmployeePo(employeePo);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<?> deleteEmployeePo(@PathVariable Integer id){
        employeeService.deleteEmployeePo(id);
        return Result.success();
    }
}
